﻿using emailBoom.Properties;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Reflection;
using System.Resources;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml;

namespace emailBoom
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            //读取配置文件
            XmlDocument xmldoc = new XmlDocument();
            xmldoc.LoadXml(Resources.ResourceManager.GetObject("EmailSetting").ToString());
            
            

            string toEmail = xmldoc.SelectSingleNode("/ROOT/boom/toEmailGroup/toEmail").InnerText;

            string fromEmail = xmldoc.SelectSingleNode("/ROOT/FromEmail").InnerText;
            string fromEmailKey = xmldoc.SelectSingleNode("/ROOT/FromEmailKey").InnerText;
            string fromEmailSMTP = xmldoc.SelectSingleNode("/ROOT/FromEmailSMTP").InnerText;
            string subject = xmldoc.SelectSingleNode("/ROOT/Register/Subject").InnerText;
            string body = xmldoc.SelectSingleNode("/ROOT/Register/Body").InnerText;



            //邮件参数配置
            MailMessage mailObj = new MailMessage();
            mailObj.From = new MailAddress(fromEmail); //发送人邮箱地址
            mailObj.To.Add(toEmail);   //收件人邮箱地址
            mailObj.Subject = subject;    //主题
                                          //mailObj.Body               = "<a href='http://localhost:59446/#!/home/emailRegisterIng/" + email + "?tempKey=" + tempKey + "' target='_blank'>点击此处进行激活</a>";    //正文
            mailObj.Body = body;
            mailObj.IsBodyHtml = true;
            SmtpClient smtp = new SmtpClient();
            smtp.Host = fromEmailSMTP;         //smtp服务器名称
            smtp.UseDefaultCredentials = true;
            smtp.Credentials = new NetworkCredential(fromEmail, fromEmailKey);  //发送人的登录名和密码
            smtp.Send(mailObj);
          
        }
    }
}
